/**
 * 用户相关接口
 */
import request from '../utils/request'

export default {
  // 修改地址
  updateAddress (val) {
    const data = {
      id: val.id,
      receiver: val.name,
      telephone: val.tel,
      district: val.county,
      province: val.province,
      city: val.city,
      areaCode: val.areaCode,
      addrDetail: val.addressDetail,
      isDefault: val.isDefault === true ? 1 : 0
    }
    return request({
      url: 'address/editAddress.do_',
      method: 'post',
      data
    })
  },
  // 获取用户默认地址
  getDefaultAddress () {
    return request({
      url: 'address/getDefaultAddress.do_',
      method: 'post'
    })
  },
  // 获取用户地址
  getAddress (id) {
    const data = {
      id: id
    }
    return request({
      url: 'address/getAddressById.do_',
      method: 'post',
      data
    })
  },
  // 删除地址
  deleteAddress (val) {
    const data = {
      id: val.id
    }
    return request({
      url: 'address/deleteAddress.do_',
      method: 'post',
      data
    })
  },

  // 获取地址列表
  getAddressList (id) {
    const data = {
      id: id
    }
    return request({
      url: 'address/getAddressList.do_',
      method: 'post',
      data
    })
  },
  // 新增地址
  addAddress (val) {
    const data = {
      id: val.id,
      receiver: val.name,
      telephone: val.tel,
      district: val.county,
      province: val.province,
      city: val.city,
      areaCode: val.areaCode,
      addrDetail: val.addressDetail,
      isDefault: val.isDefault === true ? 1 : 0
    }
    return request({
      url: 'address/addAddress.do_',
      method: 'post',
      data
    })
  },
  // 注册时发送验证码
  createCode (phone) {
    const data = {
      telephone: phone
    }
    return request({
      url: 'member/createCode.do_',
      method: 'post',
      data
    })
  },
  // 会员注册
  memberRegister (phone, telCode, password) {
    const data = {
      telephone: phone,
      telCode: telCode,
      password: password
    }
    return request({
      url: 'member/memberRegister.do_',
      method: 'post',
      data
    })
  },
  // 会员登陆
  memberLogin (telephone, password) {
    const data = {
      telephone: telephone,
      password: password
    }
    return request({
      url: 'member/memberLogin.do_',
      method: 'post',
      data
    })
  },
  //
  // 注册时发送验证码
  passwordCode (phone) {
    const data = {
      telephone: phone
    }
    return request({
      url: 'member/passwordCode.do_',
      method: 'post',
      data
    })
  },
  // 重置密码
  memberPassword (phone, telCode, password) {
    const data = {
      telephone: phone,
      telCode: telCode,
      password: password
    }
    return request({
      url: 'member/memberPassword.do_',
      method: 'post',
      data
    })
  },
  // 充值金额
  chargeBalance (balance) {
    const data = {
      balance: balance
    }
    return request({
      url: 'member/chargeBalance.do_',
      method: 'post',
      data
    })
  },
  // 查询会员的详细信息
  getMemberDetailById () {
    return request({
      url: 'member/getMemberDetailById.do_',
      method: 'get'
    })
  },
  // 查询会员信息
  getMemberInfoById () {
    return request({
      url: 'member/getMemberInfoById.do_',
      method: 'get'
    })
  },
  // 更改会员信息
  editMemberInfo (userInf) {
    const data = {
      nickname: userInf.nickname,
      email: userInf.email,
      sex: userInf.sex,
      imageUrl: userInf.imageUrl
    }
    return request({
      url: 'member/editMemberInfo.do_',
      method: 'post',
      data
    })
  },
  // 修改密码发送验证码
  sendCode (oldpassword, newpassword, confirmpassword) {
    return request({
      url: 'member/sendCode.do_',
      method: 'get',
      params:
      {
        oldpassword: oldpassword,
        newpassword: newpassword,
        confirmpassword: confirmpassword
      }
    })
  },
  // 修改会员密码
  editMemberPassword (code, oldpassword, newpassword, confirmpassword) {
    const data = {
      code: code,
      oldpassword: oldpassword,
      newpassword: newpassword,
      confirmpassword: confirmpassword
    }
    return request({
      url: 'member/editMemberPassword.do_',
      method: 'post',
      data
    })
  },
  // 显示会员消息
  queryMessageList (currentPage, pageSize) {
    return request({
      url: 'member/queryMessageList.do_',
      method: 'get',
      params: {
        currentPage: currentPage,
        pageSize: pageSize
      }
    })
  },
  // 更新消息的状态
  updateMessageStatus (id, isRead) {
    const data = {
      id: id,
      isRead: isRead
    }
    return request({
      url: 'member/updateMessageStatus.do_',
      method: 'post',
      data
    })
  },
  // 通过消息id查询一条消息
  queryOneMessageById (messageId) {
    return request({
      url: 'member/queryOneMessageById.do_',
      method: 'get',
      params: {
        messageId: messageId
      }
    })
  },
  // 获取评价状态商品详情
  getCommentGoodsCount () {
    return request({
      url: '/order/getCommentGoodsCount.do_',
      method: 'get'
    })
  },
  // 获取充值记录
  getRechargeDetail (currentPage, pageSize) {
    return request({
      url: 'rechargeHistory/getHistoryList.do_',
      method: 'post',
      data: {pageSize: pageSize, currentPage: currentPage}
    })
  }
}
